package com.xq.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author xq
 * @version 1.0
 * @date 2021/4/17 17:27
 * @description 拦截器 可以拦截访问路径
 */
public class MyInterceptor implements HandlerInterceptor {

    /**
     * 预先处理拦截方法
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("preHandle：预先处理拦截方法");
        return true;
    }

    /**
     * 后期处理拦截方法
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle：后期处理拦截方法");
    }

    /**
     * 完成后拦截方法
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("afterCompletion：完成后拦截方法");
    }
}
